# coding=utf-8
"""
作者：董新强 
创建时间：2019-2-21
描述：定时任务
"""
import sched
import time


class Schedule():
    def __init__(self):
        self.schedule = sched.scheduler(time.time, time.sleep)

    def perform_command(self, cmd, inc):
        self.schedule.enter(inc, 0, self.perform_command, (cmd, inc))
        try:
            cmd()
        except Exception as e:
            print(e)

    def start(self, cmd, inc=60):
        self.schedule.enter(inc, 0, self.perform_command, (cmd, inc))
        self.schedule.run()


if __name__ == '__main__':
    def cmd():
        print('this is cmd %f' % (time.time()))


    inst = Schedule()
    inst.start(cmd, 20)
